package com.ruoyi.web.controller.cashier;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SyBillLadingDetails;
import com.ruoyi.system.domain.SyTraditionalReservation;
import com.ruoyi.system.dto.SyTraditionalReservationDTO;
import com.ruoyi.system.enumeration.SyTraditionalReservationEnum;
import com.ruoyi.system.service.SyTraditionalReservationService;
import com.ruoyi.system.util.BaseResponse;
import com.ruoyi.system.util.StoreIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/reservation")
@Api(tags = "传统预定管理")
@Anonymous
public class SyTraditionalReservationController extends BaseController {

    @Autowired
    private SyTraditionalReservationService reservationService;

    @Autowired
    private StoreIdUtils storeIdUtils;


    @ApiOperation("桌台预定")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SyTraditionalReservationDTO reservationDTO) {
        Boolean add = reservationService.add(reservationDTO);
        return AjaxResult.success(add);
    }


    @PostMapping("/list")
    @ApiOperation("获取预定列表")
    public BaseResponse<IPage<SyTraditionalReservation>> list(@RequestBody SyTraditionalReservation reservation) {
        IPage<SyTraditionalReservation> list = reservationService.list(reservation);
        return BaseResponse.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation("获取预定详情")
    public BaseResponse<SyTraditionalReservation> detail(Long id) {
        if (id == null) {
            return BaseResponse.error("参数不能为空");
        }
        LambdaQueryWrapper<SyTraditionalReservation> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(SyTraditionalReservation::getId, id);
        wrapper.eq(SyTraditionalReservation::getStoreId,storeIdUtils.getStoreId());
        SyTraditionalReservation one = reservationService.getOne(wrapper);
        one.setStatusDesc(SyTraditionalReservationEnum.getValueByKey(one.getStatus()));
        return BaseResponse.success(one);
    }

    @PutMapping("/update")
    @ApiOperation("修改预定")
    public AjaxResult update(@RequestBody SyTraditionalReservation reservationDTO) {
        Boolean update = reservationService.update(reservationDTO);
        return AjaxResult.success(update);
    }

    /**
     * 开单
     */
    @PostMapping("/openOrder")
    @ApiOperation("开单")
    public AjaxResult openOrder(@RequestBody SyBillLadingDetails syBillLadingDetails) {
        Boolean update = reservationService.openOrder(syBillLadingDetails);
        return AjaxResult.success(update);
    }

}
